<?php
include_once './config.php';

// 根据前端的传参,来执行数据库查询操作
// 将查询结果的数组,以json串的形式返回给前端

// 接收参数
$name = $_POST['name'];
$newpwd = $_POST['newpwd'];
$oldpwd = $_POST['oldpwd'];
$result;

// 链接数据库,执行查询语句

$link = mysqli_connect($host, $user, $pwd, $dbname, $port);

$sqlselect = "SELECT pwd from user where name = '$name'; ";
$resultselect = mysqli_query($link, $sqlselect);
$arr = mysqli_fetch_all($resultselect , MYSQLI_ASSOC);
$pwd = $arr[0]['pwd'];

if($pwd == $oldpwd){

    $sql = "UPDATE user set pwd = '$newpwd' where name = '$name'; ";
    $result = mysqli_query($link, $sql);   
}else{
    $result = false;
}

echo json_encode($result);